import request from '@/utils/request'
export interface PageQuery {
  current?: number
  size?: number
}

export function listGenTables(params: { module?: string } & PageQuery) {
  return request.get('/gen/tables', { params })
}

export function getGenTable(id: number) {
  return request.get(`/gen/tables/${id}`)
}

export function saveGenTable(data: any) {
  return request.post('/gen/tables', data)
}

export function listGenColumns(id: number) {
  return request.get(`/gen/tables/${id}/columns`)
}

export function saveGenColumns(id: number, data: any[]) {
  return request.post(`/gen/tables/${id}/columns/batch`, data)
}

export function introspectColumns(id: number) {
  return request.post(`/gen/tables/${id}/introspect-columns`)
}

export function validateQueryDefs(id: number) {
  return request.post(`/gen/tables/${id}/validate-query-defs`)
}

export function previewGenerate(id: number) {
  return request.post(`/gen/tables/${id}/preview`)
}

export function doGenerate(id: number) {
  return request.post(`/gen/tables/${id}/generate`)
}

export function downloadZip(id: number) {
  return request.post(`/gen/tables/${id}/download-zip`, {}, { responseType: 'blob' })
}

export function generateToProject(id: number, params: { targetModule?: string, overwrite?: boolean }) {
  return request.post(`/gen/tables/${id}/generate-to-project`, params)
}

export function batchGenerate(ids: number[]) {
  return request.post('/gen/tables/batch-generate', { tableIds: ids })
}

export function batchPreview(ids: number[]) {
  return request.post('/gen/tables/batch-preview', { tableIds: ids })
}

export function deleteGenTable(id: number) {
  return request.delete(`/gen/tables/${id}`)
}

export function batchDeleteGenTables(ids: number[]) {
  return request.post('/gen/tables/batch-delete', ids)
}

export function deleteGenColumn(id: number, colId: number) {
  return request.delete(`/gen/tables/${id}/columns/${colId}`)
}

export function listDbTables(params?: { schema?: string; nameLike?: string }) {
  return request.get('/gen/db/tables', { params })
}

export function validateTableConfig(id: number) {
  return request.post(`/gen/tables/${id}/validate-config`)
}

export function recommendConfig(data: { tableName: string, columns?: any[] }) {
  return request.post('/gen/tables/recommend-config', data)
}


